package interview.huawei.tjt.od;

import java.util.Arrays;

/**
 * @Author CandyWall
 * @Date 2022/2/22--15:58
 * @Description
 */
public class P3_2 {
    public static void main(String[] args) {
        /*int[][] lis = {{2, 1, 1},
                       {1, 2, 1},
                       {3, 1}, 
                       {1, 1, 2}, 
                       {1, 1, 1, 1}};*/
        int[][] lis = {{2, 1, 1, 2},
                       {1, 2, 1, 1, 1},
                       {3, 1, 2},
                       {1, 1, 2, 2},
                       {1, 1, 1, 2, 1}};
        // 计算墙的宽度
        int width = 0;
        for (int i = 0; i < lis[0].length; i++) {
            width += lis[0][i];
        }
        // 统计缝隙位置
        int[] creviceArray = new int[width];
        for (int i = 0; i < lis.length; i++) {
            int disToLeft = 0;
            for (int j = 0; j < lis[i].length - 1; j++) {
                disToLeft += lis[i][j];
                creviceArray[disToLeft]++;
            }
        }

        // 找到缝隙最多的位置
        int maxBreakBricks = creviceArray[1];
        for (int i = 2; i < width; i++) {
            if (maxBreakBricks < creviceArray[i]) {
                maxBreakBricks = creviceArray[i];
            }
        }
        System.out.println(Arrays.toString(creviceArray));

        // 缝隙最多的位置劈下去劈的砖块数量最少
        System.out.println(lis.length - maxBreakBricks);
    }
}